package hello;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;


public class HelloCanvas extends MIDlet{

	protected void startApp() throws MIDletStateChangeException {
		ACanvas myCanvas = new ACanvas(20,100);
		Display myDisplay = Display.getDisplay(this);
		myDisplay.setCurrent(myCanvas);
		while(true){
			myCanvas.repaint();
		}
	}

	//make a class within the midlet class that is a canvas
	public class ACanvas extends Canvas{
		
		int x=0;
		int y=0;
		int dir = 1;
		
		ACanvas(int _x, int _y){
			x = _x;
			y = _y;	
		}
	
		protected void paint(Graphics g) {
			g.setColor(255);
			g.fillRect(0, 0, getWidth(), getHeight());
			
			x = x + dir;
			if (x > getWidth()){
				dir = -dir;
			}
			if (x <0 ){
				dir = -dir;
			}
			g.setColor(0);
			g.drawString("Hello", x, y,0);
		}
		
		
	}
	
	
	
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {

	}

	protected void pauseApp() {
		
	}

}
